import pandas as pd
from wordcloud import WordCloud
import matplotlib.pyplot as plt  # 绘制图像的模块
from PIL import Image, ImageTk
import numpy as np


def word_cloud():
    """
    生成中国疫情累计确诊人数top10的省份词云
    :return:
    """
    pandas_data = pd.read_csv("data/metadata/currentConfirmedCount_china.csv", index_col=0, dtype=np.int32)
    top = pandas_data.iloc[4:, :10]
    datelist = list(top.index)
    date_index = datelist.index(20210101)
    top = top.iloc[date_index:]
    name_color_name = top.columns
    cut_text = " ".join(list(name_color_name))
    wordcloud = WordCloud(
        # 设置字体，不然会出现口字乱码，文字的路径是电脑的字体一般路径，可以换成别的
        font_path="C:/Windows/Fonts/simfang.ttf",
        # 设置了背景，宽高
        background_color="white", width=600, height=600).generate(cut_text)
    print(cut_text)
    wordcloud.to_file('./data/image/words.png')
    plt.imshow(wordcloud, interpolation="bilinear")
    plt.axis("off")
    im = Image.open('data/image/words.png')
    im.show()


def information():
    data = pd.read_json("data/metadata/DXYOverall.json")
    print(data)